import threading, thread
import gobject, gtk

gtk.gdk.threads_init()

class PygtkThread(object):
   def __init__(self, thread_action, thread_callback,*thread_callback_args):
       self.thread_action = thread_action
       self.thread_callback = thread_callback
       self.thread_callback_args = thread_callback_args
       
   def _start(self,*args):
        self.thread_action(*args)
        if len(self.thread_callback_args) > 0:
            gobject.idle_add(self.thread_callback,self.complete_callback_args)
        else:
            gobject.idle_add(self.thread_callback)
   
   def start(self, *args):
       threading.Thread(target=self._start, args=args).start()
   
   def stop(self):
       self._stopped = True